<template>
  <div class="app-container">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="姓名" prop="name">
        <el-input v-model="ruleForm.name" placeholder="Xm"></el-input>
      </el-form-item>

      <el-form-item label="生日" required>
        <el-col :span="11">
          <el-form-item prop="date1">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="ruleForm.date1"
              style="width: 100%;"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="date2">
            <el-time-picker
              placeholder="选择时间"
              v-model="ruleForm.date2"
              style="width: 100%;"
            ></el-time-picker>
          </el-form-item>
        </el-col>
      </el-form-item>

      <el-form-item label="微信" prop="vx">
        <el-input v-model="ruleForm.vx" placeholder="微信"></el-input>
      </el-form-item>

      <el-form-item label="QQ" prop="qq">
        <el-input v-model="ruleForm.qq" placeholder="QQ"></el-input>
      </el-form-item>

      <el-form-item label="性别" prop="sex">
        <el-radio-group v-model="ruleForm.sex">
          <el-radio label="男"></el-radio>
          <el-radio label="女"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="个人简介" prop="desc">
        <el-input type="textarea" v-model="ruleForm.desc" placeholder="介绍一下你自己吧"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >更新</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    var d=new Date();
    return {
      ruleForm: {
        name: "Xm",
        vx: "微信",
        qq:"QQ",
        date1: d.getFullYear(),
        date2: d.getDate(),
        sex: "男",
        desc: "介绍一下你自己吧"
      },
      rules: {
        name: [
          { required: true, message: "请输入你的姓名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        vx: [
          { required: true, message: "请输入你的微信账号", trigger: "blur" },
          { min: 3, max: 11, message: "长度在 3 到 11 个字符", trigger: "blur" }
        ],
        qq: [
          { required: true, message: "请输入你的qq账号", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" }
        ],
        date1: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change"
          }
        ],
        date2: [
          {
            type: "date",
            required: true,
            message: "请选择时间",
            trigger: "change"
          }
        ],
        sex: [{ required: true, message: "请选择您的性别", trigger: "change" }],
        desc: [
          { required: true, message: "请填写您的个人简介", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
      this.$store.commit("PersonModule/changePerson",this.ruleForm)
      // this.$store.commit("PersonModule/changePersonP",this.ruleFormP)
      this.$router.go(-1)
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
};
</script>
